/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ages.graphics

import com.ages.env.Options
import javax.media.opengl.GL
import javax.media.opengl.glu.GLU

object ViewportSwitcher {

  val VIEW_2D = 0
  val VIEW_3D = 1
  val NOT_SET = -1
  var currentView:Int = NOT_SET

  def setup3DView(gl:GL)
  {
    if(currentView!=VIEW_3D)
    {
      currentView = VIEW_3D

      gl.glViewport(0, 0, Options.width, Options.height)

//    println("reshaped...")
      gl.glMatrixMode(GL.GL_PROJECTION);						// Select The Projection Matrix
      gl.glLoadIdentity();
      val glu = new GLU()
      glu.gluPerspective(60, Options.width.toDouble/Options.height.toDouble, 0.5, 10000)

      gl.glShadeModel(GL.GL_SMOOTH);                            //Enables Smooth Color Shading
      gl.glClearColor(1,1,1,1);               //This Will Clear The Background Color To Black
      gl.glClearDepth(1.0);                                  //Enables Clearing Of The Depth Buffer
      gl.glEnable(GL.GL_DEPTH_TEST);                            //Enables Depth Testing
      gl.glDepthFunc(GL.GL_LEQUAL);                             //The Type Of Depth Test To Do
      gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);  // Really Nice Perspective Calculations
      gl.glMatrixMode(GL.GL_MODELVIEW)
      gl.glEnable(GL.GL_LIGHTING)
    }
  }
  
  def setup2DView(gl:GL)
  {
//    gl.glViewport(0, 0, Options.width, Options.height)
    if(currentView!=VIEW_2D)
    {
      currentView=VIEW_2D
      gl.glMatrixMode(GL.GL_PROJECTION);
      gl.glLoadIdentity;
      val glu = new GLU()
      glu.gluOrtho2D(0, Options.width, 0, Options.height);
      gl.glMatrixMode(GL.GL_MODELVIEW)
      gl.glDisable(GL.GL_LIGHTING)
    }
//          gl.glMatrixMode(GL.GL_MODELVIEW)
//      gl.glDisable(GL.GL_LIGHTING)
  }


}
